package com.wwwarehouse.resource_center.fragment.createobject.creategoods;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;

import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.resource_center.R;
import com.wwwarehouse.resource_center.adapter.rules.GoodsSelectAttributeAdapter;
import com.wwwarehouse.resource_center.bean.goods.GoodsAttributesBean;
import com.wwwarehouse.resource_center.fragment.rules.TheParentFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Joseph on 2017/9/23.
 *         <p/>
 *         已经选择的属性
 */

public class GoodsAttributesHaveChosenSelectChildFragment extends TheParentFragment {

    public RecyclerView mRvContent;
    public GoodsSelectAttributeAdapter mAdapter;
    public List<GoodsAttributesBean.ListBean> tagBeanList = new ArrayList<>();
    public List<GoodsAttributesBean.ListBean> mData = new ArrayList<>();

    @Override
    protected int getContentId() {
        return R.layout.fragment_rule_select_application_objectst;
    }

    @Override
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
        return null;
    }

    @Override
    public void onReLoad(int code) {

    }

    @Override
    protected void init(View view) {
        mRvContent = findView(view, R.id.rv_content);
        mRvContent.setLayoutManager(new GridLayoutManager(mActivity, 3) {
            @Override
            public boolean canScrollHorizontally() {
                return false;
            }

            @Override
            public boolean canScrollVertically() {
                return false;
            }

        });
    }

    @Override
    protected void loadDatas() {
        Bundle b = getArguments();
        tagBeanList = b.getParcelableArrayList("data");
        mData = new ArrayList<>();
        int pos = b.getInt("pos");
        int num = b.getInt("num");
        for (int i = pos * num; i < num + pos * num; i++) {
            if (i >= 0 && i < tagBeanList.size()) {
                mData.add(tagBeanList.get(i));
            }
        }
        final ViewTreeObserver observer = mRvContent.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                observer.removeGlobalOnLayoutListener(this);
                setHeight(mRvContent.getHeight(), mRvContent.getWidth());
            }
        });
    }

    public void setHeight(int height, int Width) {
        mAdapter = new GoodsSelectAttributeAdapter(mActivity, mData, height, Width);
        mRvContent.setAdapter(mAdapter);
    }
    @Override
    public void onSuccess(CommonClass commonClass, int what) {

    }

}
